package com.mybatiscore.jiaocheng.d02mybatis参数;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class d02Map_POJO参数 {
    //Map集合为参数
    @Test
    public void insertMap(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        Map<String,Object> map=new HashMap<>();
        map.put("name","王五");
        map.put("age",18);
        map.put("heightT",1.80);
        map.put("sex",'男');
        map.put("birth",new Date());
        mapper.insertMap(map);
        sqlSession.commit();
        sqlSession.close();
    }

    //POJO
    @Test
    public void insertPOJO(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        mapper.insertPOJO(new Student(null,"李是",18,1.81,new Date(),'男'));
        sqlSession.commit();
        sqlSession.close();

    }
}
